import axios from "axios";
import Vue from 'vue'
import { BASE_URL } from '@/config'
import { SUBJECT_TYPE } from "@/config/enum";
const instance = axios.create({
    baseURL: BASE_URL,
    // headers: { 'X-Custom-Header': 'foobar' }
});
Vue.mixin({
    filters:{
        fmtSubjectType(val){
            return ['单选题','多选题','判断题','填空题'][val]
        },
        fmtOrder2ABC(val) {
            return 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[val]
        }
    },
    data() {
        return {
            SUBJECT_TYPE
        }
    },
    methods: {
        async $get(url,params){
            try {
                let {data} = await instance.get(url,{params})
                return data
            } catch (error) {
                return error
            }
        },
        async $post(url,params){
            let {data} = await instance.post(url,params)
            return data
        },
        checkisXZT(type){
            return type === this.SUBJECT_TYPE.DANXUAN || type === this.SUBJECT_TYPE.DUOXUAN
        }
    },
})